#include <stdlib.h>
#include <stdio.h>
#include "lexer.h"
#include "parser.h"

void
choosebuffer (int argc, const char *fname)
{
  switch (argc)
    {
    case 2:
      if ((tape = fopen (fname, "r")) == NULL)
	{
	  fprintf (stderr, "simpas: cannot open for read %s... exiting\n",
		   fname);
	  exit (-2);
	}
      break;
    case 1:
      tape = stdin;
      break;
    default:
      printf ("usage: simpas <file>.pas\n");
      exit (-1);
    }
}

void
bootparser (void)
{
  lookahead = gettoken ();
}

main (int argc, const char *argv[])
{
  choosebuffer (argc, argv[1]);
  /* boot the parser */
  bootparser ();
  /* call the syntax start symbol */
  program ();
}
